var initHeatmap;
var heatmapRenderer

require(["esri/renderers/HeatmapRenderer"],
    function (HeatmapRenderer) {

        //本地数据添加文件解析结果
        $("#addData_iframeContent").on("load", function () {
            var responseText = $("#addData_iframeContent")[0].contentDocument.body.getElementsByTagName("pre")[0].innerHTML;

            fileParse(responseText, "lcoalLayerList");
            $("#addDataModal").modal('hide');
            $("#addRouteModal").modal('hide');
        });

        //区域覆盖分析文件解析结果
        $("#areaCoverage_iframeContent").on("load", function () {
            var responseText = $("#areaCoverage_iframeContent")[0].contentDocument.body.getElementsByTagName("pre")[0].innerHTML;
            fileParse(responseText, "areaCoverageLayerList");

            $("#areaCoverageModal").modal('hide');
        });



        //轨迹分析文件解析结果
        $("#routeFileUpload0_iframeContent").on("load", function () {
            var responseText = $("#routeFileUpload0_iframeContent")[0].contentDocument.body.getElementsByTagName("pre")[0].innerHTML;
            fileParse(responseText, "routeExceptionLayerList");
        });


        $("#routeFileUpload1_iframeContent").on("load", function () {
            var responseText = $("#routeFileUpload1_iframeContent")[0].contentDocument.body.getElementsByTagName("pre")[0].innerHTML;
            fileParse(responseText, "routeExceptionLayerList");
        });



        //区域特征分析解析结果
        initHeatmap = function (fLayer) {
            const heatmapRenderer = new HeatmapRenderer({
                // field: field,
                blurRadius: 20,
                maxPixelIntensity: 250,
                minPixelIntensity: 10

            });
            fLayer.setRenderer(heatmapRenderer);
            // fLayer.redraw();
            fLayer.setVisibility(true);
        }

        $("#areaFeature_iframeContent").on("load", function () {
            var responseText = $("#areaFeature_iframeContent")[0].contentDocument.body.getElementsByTagName("pre")[0].innerHTML;
            $("#areaFeatureModal").modal('hide');


            if (areaFeatureType == "heatmap") {
                fileParse(responseText, "heatmapLayerList");

                areaFeatureType = ""
                var interval1 = setInterval(function () {
                    initHeatmap(localDataFeatureLayers[localDataFeatureLayers.length - 1]);
                    window.clearInterval(interval1);
                }, 500);
                $("#areaFeaturePanel").show();


                $(".addui-slider.addui-slider-horizontal").mouseup(function () {
                    var blurRadius = $(".addui-slider-input").attr("value");
                    heatmapRenderer.setBlurRadius(blurRadius);

                    var zTree1 = $.fn.zTree.getZTreeObj('heatmapLayerList');
                    var subNodes = zTree1.getNodes()[0].children;
                    subNodes.forEach(item => {
                        layerId = item.layerId;
                        map.getLayer(layerId).setRenderer(heatmapRenderer);
                        map.getLayer(layerId).redraw();
                    })
                });

                $(".addui-slider.addui-slider-horizontal").click(function () {
                    var blurRadius = $(".addui-slider-input").attr("value");
                    heatmapRenderer.setBlurRadius(blurRadius);

                    var zTree1 = $.fn.zTree.getZTreeObj('heatmapLayerList');
                    var subNodes = zTree1.getNodes()[0].children;
                    subNodes.forEach(item => {
                        layerId = item.layerId;
                        map.getLayer(layerId).setRenderer(heatmapRenderer);
                        map.getLayer(layerId).redraw();
                    })

                    // var blurRadius = $(".addui-slider-input").attr("value");
                    // heatmapRenderer.setBlurRadius(blurRadius);
                    // localDataFeatureLayers[localDataFeatureLayers.length - 1].setRenderer(heatmapRenderer);
                    // localDataFeatureLayers[localDataFeatureLayers.length - 1].redraw();
                });
            } else if (areaFeatureType == "cluster") {
                fileParse(responseText, "clusterLayerList");

                // areaFeatureType = ""
            }


        });

        //热力程度设置
        var blurRadius = $(".addui-slider-input").attr("value");

        heatmapRenderer = new HeatmapRenderer({
            // field: field,
            blurRadius: blurRadius,
            maxPixelIntensity: 250,
            minPixelIntensity: 10
        });



    });